package com.eascs.ticket.project.controller;

import javax.inject.Inject;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.eascs.common.util.ObjectUtil;
import com.eascs.site.view.HtmlRestResult;
import com.eascs.site.view.MessageRestResult;
import com.eascs.site.view.ViewContext;
import com.eascs.ticket.common.controller.BaseActionRestController;
import com.eascs.ticket.project.entity.ProjectModule;
import com.eascs.ticket.project.entity.ProjectModuleUpdate;
import com.eascs.ticket.project.form.GetInsertProjectModulePageForm;
import com.eascs.ticket.project.form.GetUpdateProjectModulePageForm;
import com.eascs.ticket.project.form.ProjectModuleInsertForm;
import com.eascs.ticket.project.form.ProjectModuleRemoveForm;
import com.eascs.ticket.project.form.ProjectModuleUpdateForm;
import com.eascs.ticket.project.service.ProjectModuleService;

@RestController
public class ProjectModuleRestController extends BaseActionRestController {

	@Inject
	private ProjectModuleService projectModuleService;

	@RequestMapping(value = "/project/ticket-module/remove")
	public MessageRestResult removeProjectModule(ProjectModuleRemoveForm projectModuleRemoveForm) {
		projectModuleService.removeProjectModule(projectModuleRemoveForm.getId());
		return MessageRestResult.refresh();
	}

	@RequestMapping(value = "/project/ticket-module/insert")
	public MessageRestResult insertProjectModule(ProjectModuleInsertForm projectModuleInsertForm) {
		ProjectModule projectModule = new ProjectModule();
		ObjectUtil.copySimpleProperties(projectModuleInsertForm, projectModule);
		projectModuleService.insertProjectModule(projectModule);
		return MessageRestResult.refresh();
	}

	@RequestMapping(value = "/project/ticket-module/update")
	public MessageRestResult updateProjectModule(ProjectModuleUpdateForm projectModuleUpdateForm) {
		ProjectModuleUpdate projectModuleUpdate = new ProjectModuleUpdate();
		ObjectUtil.copySimpleProperties(projectModuleUpdateForm, projectModuleUpdate);
		projectModuleService.updateProjectModule(projectModuleUpdate);
		return MessageRestResult.refresh();
	}

	@RequestMapping(value = "/project/ticket-module/getInsertProjectModulePage")
	public HtmlRestResult getInsertProjectModulePage(GetInsertProjectModulePageForm getInsertProjectModulePageForm) {
		ViewContext.put("projectId", getInsertProjectModulePageForm.getProjectId());
		return HtmlRestResult.popHtmlFragment("project/getInsertProjectModulePage");
	}

	@RequestMapping(value = "/project/ticket-module/getUpdateProjectModulePage")
	public HtmlRestResult getUpdateProjectModulePage(GetUpdateProjectModulePageForm getUpdateProjectModulePageForm) {
		ProjectModule projectModule = this.projectModuleService.getProjectModuleById(getUpdateProjectModulePageForm.getId());
		ViewContext.put("projectModule", projectModule);
		return HtmlRestResult.popHtmlFragment("project/getUpdateProjectModulePage");
	}

}
